/**
 * GenericDAO.java
 *
 * Created on 06 Jul 2010 14:33:11
 */
package org.blueoxygen.cimande.persistence.dao;

import java.util.List;

import javax.annotation.PostConstruct;

import org.blueoxygen.cimande.persistence.PersistenceManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author Dian Wahyu Aditya
 *
 */
@Service
public class GenericDAO<T> {
	@Autowired
	protected PersistenceManager manager;
	protected Class<T> clazz;

	public void save(T objectToSave) {
		manager.save(objectToSave);
	}

	public void remove(T objectToRemove) {
		manager.remove(objectToRemove);
	}

	@SuppressWarnings("unchecked")
	public T getById(Class<T> type, long id) {
		return (T) manager.getById(type, id);
	}

	@SuppressWarnings("unchecked")
	public T getByUniqueField(Class<T> type, Object pk, String fieldName) {
		return (T) manager.getByUniqueField(type, pk, fieldName);
	}

	@SuppressWarnings("unchecked")
	public List<T> findAll(Class<T> type) {
		return manager.findAll(type);
	}

	@SuppressWarnings("unchecked")
	public List<T> findAllSorted(Class<T> type, String sortProperty) {
		return manager.findAllSorted(type, sortProperty);
	}

	@SuppressWarnings("unchecked")
	public List<T> findAllSortedDirected(Class<T> type, String sortField,
			String direction) {
		return manager.findAllSortedDirected(type, sortField, direction);
	}

	@SuppressWarnings("unchecked")
	@Deprecated
	public List<T> find(String query, Object[] parameters,
			Class<T>[] parameter_types) {
		return manager.find(query, parameters, parameter_types);
	}

	@SuppressWarnings("unchecked")
	public List<T> getList(String query, Object[] parameters,
			Class<T>[] parameter_types) {
		return manager.getList(query, parameters, parameter_types);
	}

	@SuppressWarnings("unchecked")
	public T getById(Class<T> type, String id) {
		return (T) manager.getById(type, id);
	}
}
